package com.sz.exce.service.impl;

import com.sz.exce.dao.LogDao;
import com.sz.exce.entity.Log;
import com.sz.exce.service.LogService;
import com.sz.exce.vo.LogQueryVO;
import com.sz.exce.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogServiceImpl implements LogService {
    @Autowired
    LogDao logDao;

    public LogQueryVO getLogs(PageVO vo) {

        LogQueryVO queryVO = new LogQueryVO();
        vo.setStart((vo.getIndex()-1)*vo.getPageSize()+1);
        vo.setEnd(vo.getIndex()*vo.getPageSize());
        Integer pageCount = (logDao.selectCount(vo)+vo.getPageSize()-1)/vo.getPageSize();
        List<Log> logs = logDao.selectLogs(vo);

        queryVO.setPageCount(pageCount);
        queryVO.setTransfers(logs);
        System.out.println(queryVO);
        return queryVO;
    }

    public int addLog(Log log) {
        return logDao.insert(log);
    }
}
